const express = require('express')
const router = express.Router()
const {HotpotInfo} = require('../db/schema')
const { mySend, checkParams } = require('../utils/index')

router.post('/forceOrder', (req, res) => {
  const { thermotankNo, place, forceLock, send } = req.body
  console.log(thermotankNo, place, forceLock, send)
  const checked = checkParams({ thermotankNo, place, forceLock, send })
  if (checked) return mySend(res, 1, checked)
  if(!(thermotankNo == '1' || thermotankNo == '2')){
    return mySend(res, 1, '保温柜编号不正确,thermotankNo=' + thermotankNo)
  }

  if(place * 1 > 20 || place * 1 < 1){
    return mySend(res, 1, '保温柜格子不正确,place=' + place)
  }
  let forceOrder = "170,6,0,6,0";
  forceOrder += (',' + thermotankNo);
  forceOrder += (',' + place);
  

  

  if(!(forceLock == 1 || forceLock == 2)){
    return mySend(res, 1, 'forceLock不正确,forceLock=' + forceLock)
  }
  if(!(send == 1 || send == 2)){
    return mySend(res, 1, 'send不正确,send=' + send)
  }
  console.log({forceLock: forceLock * 1, send: send * 1, forceOrder})
  HotpotInfo.updateOne({storeId: '1213663903522160642'}, {forceLock: forceLock * 1, send: send * 1, forceOrder}).then(result => {
    if(result){
      return mySend(res, 0, '修改成功', result)
    }else{
      return mySend(res, 1, '修改失败', result)
    }
  }).catch(error => {
    return mySend(res, 2, '失败', error)
  })

})

module.exports = router